package com.lovemanai.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.lovemanai.service.Person;

public class Demo1 {

	@Test
	public void test1() {
		
		AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		
		Person chinese = ctx.getBean("chinese", Person.class);
		
		chinese.useAxe();
		//为Spring容器注册关闭钩子
		ctx.registerShutdownHook();
	}
	
	@Test
	public void test2() {
		
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		
		Person p1 = ctx.getBean("american", Person.class);
		Person p2 = ctx.getBean("american", Person.class);
		System.out.println(p1 == p2);//Person实例时singleton bean
		p1.hunt();
		p2.hunt();
		
		
		/*
		 *  输出结果
		    true
			我带着com.lovemanai.service.impl.Dog@16022d9d去散步
			我是一只猎犬，奔跑迅速....
			我带着com.lovemanai.service.impl.Dog@7e9a5fbe去散步
			我是一只猎犬，奔跑迅速....
			//两次哈希值不一样
		 */
	}
	
}
